# -*- coding: utf-8 -*-
'''
Created on 2012-1-15

@author: y
'''

from django import forms
from django.contrib.auth.models import User
from django.forms import ModelForm, Textarea
from django.forms.widgets import TextInput
from sprt.schedule.models import Schedule, ScheduleType
import datetime
#from django.forms import ModelForm



class ComposeScheduleForm(ModelForm):
    title=forms.CharField(label="标题")
    start_date=forms.DateField(label=u'开始时间')
    end_date=forms.DateField(label=u'结束时间')
    target=forms.CharField(label=u'目标')
    schedule_type=forms.ModelChoiceField(label=u'报表类型',queryset=ScheduleType.objects.all())
    content=forms.CharField(label=u'内容')
    keyword=forms.CharField(max_length=30,label="关键字")

    class Meta:
        model = Schedule
        fields = ('title','keyword','start_date','end_date','schedule_type','target','content',)
    
    def commit_schedule(self):
        self.instance.status = 1
        self.instance.commit_date = datetime.datetime.now()
        self.save(True)
    
    def save_form(self, created_by, commit=True):
        self.instance.created_by = created_by
        self.save(True)


class ComposeReviewForm(ModelForm):
    review=forms.CharField(label=u'回顾',widget=Textarea(attrs={'cols':80,'rows':20}))
    
    class Meta:
        model = Schedule
        fields = ('review',)
    
    def commit_review(self):
        self.instance.status = 3
        self.instance.review_date = datetime.datetime.now()
        self.save(True)

